package com.web.oa.utils;

import com.web.oa.pojo.ActiveUser;
import com.web.oa.pojo.Employee;
import com.web.oa.service.EmployeeService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
/**获取报销单的上级领导*/
public class ManagerTaskHandler implements TaskListener {
    @Override
    public void notify(DelegateTask delegate) {
        //
        WebApplicationContext context= ContextLoader.getCurrentWebApplicationContext();
        //获取request
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        //Employee employee= (Employee) request.getSession().getAttribute(Constants.GLOBE_USER_SESSION);
        ActiveUser activeUser= (ActiveUser) SecurityUtils.getSubject().getPrincipal();
        //
        EmployeeService employeeService= (EmployeeService) context.getBean("employeeService");

        //获取上级
        //Long managerId = employee.getManagerId();
        Employee emg=employeeService.findEmployeeByManager(activeUser.getManagerId());
        //Employee emg= employeeService.findEmployeeByManagerId(managerId);
        delegate.setAssignee(emg.getName());
    }
}
